<script setup lang='ts'>
import { onMounted, ref, inject, watch } from 'vue';
import { searchForES3DTilesetValues } from '../../../../scripts/general';
import { copyClipboard } from './base/copyClipboard';
import { XbsjEarthUi } from '../../../../scripts/xbsjEarthUi';
import EnumProp from "./EnumProp.vue"
const xbsjEarthUi = inject('xbsjEarthUi') as XbsjEarthUi
const p = withDefaults(defineProps<{
    modelValue?: string,
    readonly?: boolean,
    name: string,
    defaultValue: any
}>(), { readonly: false, name: '' })
const emits = defineEmits(["update:modelValue", "ondrop", "ondragover", "ondragleave"]);
const list = ref<[aliasName: any, value: any][]>([['', '']])
list.value = searchForES3DTilesetValues(xbsjEarthUi, false)
// console.log(list.value);

const modelValueRef = ref<string>('')
console.log('name',p.name,p.readonly,p.defaultValue);

onMounted(() => {
    modelValueRef.value = p.modelValue ? p.modelValue : ''
})
watch(modelValueRef, (val) => {
    emits('update:modelValue', val)
})
const inputHandler = (e: any) => {
    emits('update:modelValue', (e.target.value).toString())
}
const mouseFlag = ref(false)
const resetDefult = () => {
    emits('update:modelValue', (p.defaultValue).toString())
}
</script>

<template>

    <template v-if="name === '瓦片图层'">
        <EnumProp v-model="modelValueRef" :enumStrsList="list" :withUndefined="false" :defaultValue="''"></EnumProp>
    </template>
    <template v-else>
        <div v-if="!readonly" @drop.stop="emits('ondrop', $event)" @dragover.stop="emits('ondragover', $event)"
            @dragleave.stop="emits('ondragleave', $event)">
            <div class="aa">
                <div class="string"><input type="text" :value="modelValue" @input="inputHandler($event)" /></div>
                <div class="checkbox1">
                    <div v-if="!readonly && defaultValue!==undefined && modelValue !== defaultValue" class="checkbox"
                        @click.stop.prevent="resetDefult" @mouseover="mouseFlag = true" @mouseout="mouseFlag = false">
                        <es-icon :name="'huaban'"
                            :color="mouseFlag ? 'rgba(230, 230, 230, 1)' : 'rgba(230, 230, 230, 0.4)'" :size="14" />
                    </div>
                </div>
            </div>
        </div>
        <div v-else class="aa">
            <div class="string" title="双击复制" @dblclick="copyClipboard(modelValue ?? '')">{{ modelValue }}</div>
            <div class="checkbox1">
                <div v-if="!readonly && defaultValue && modelValue !== defaultValue" class="checkbox"
                    @click.stop.prevent="resetDefult" @mouseover="mouseFlag = true" @mouseout="mouseFlag = false">
                    <es-icon :name="'huaban'" :color="mouseFlag ? 'rgba(230, 230, 230, 1)' : 'rgba(230, 230, 230, 0.4)'"
                        :size="14" />
                </div>
            </div>
        </div>
    </template>

</template>

<style scoped>
input {
    line-height: 26px;
    display: inline-block;
    width: 100%;
    height: 26px;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    margin-right: 0;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
}

input:hover {
    border: 1px solid #2c68f7;
}

input:focus {
    border: 1px solid #2c68f7;
}

.aa {
    width: 100%;
    align-items: center;
    color: rgba(230, 230, 230, 1);
    font-size: 14px;
    white-space: nowrap;
    display: flex;
}

.aa>.string {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.select {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    line-height: 26px;
    color: rgba(230, 230, 230, 1);
    position: relative;
}

.select>div {
    height: 26px;
    width: 100%;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
}

.select>ul {
    position: absolute;
    z-index: 20;
    max-height: 100px;
    left: 0;
    top: 16px;
    overflow-y: auto;
    background: #292a2e;
    box-shadow: 0px 2px 6px 0px rgba(26, 26, 28, 0.68);
    border-radius: 4px;
    overflow-x: hidden;
}

.select>ul::-webkit-scrollbar {
    width: 3px;
    background-color: rgba(41, 42, 46, 1);
    border-radius: 2px;
}

.select>ul::-webkit-scrollbar-thumb {
    background-color: rgba(183, 183, 183, 1);
    border-radius: 2px;
}

.select>ul>li {
    list-style: none;
    width: 170px;
    height: 20px;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
    text-align: left;
    padding-left: 10px;
    margin-left: -40px;
    white-space: nowrap;
    color: rgba(230, 230, 230, 1);
}

.select>ul>li:hover {
    background: #37393e;
}

.checkbox1 {
    width: 20px;
    height: 20px;
    box-sizing: border-box;
    margin-left: 10px;
    margin-top: 2px;
}

.checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    border: 1px solid rgba(230, 230, 230, 0.4);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
</style>